// web/src/app/api/(social)/members/[id]/route.ts
import {NextRequest, NextResponse} from "next/server";
import {db} from "@/lib/db";

export async function GET(req: NextRequest,
                          {params}: { params: { id: string } }
) {
    // const id = req.nextUrl.pathname.slice(
    //     req.nextUrl.pathname.lastIndexOf('/') + 1
    // );

    // const searchParams = req.nextUrl.searchParams;
    // let workspaceId = (searchParams.get('workspaceId'))
    // let userId = (searchParams.get('userId'))

    let where = {id: params.id};
    const member = await db.member.findUnique({
        where,
        include: {
            user: true,
        }
    })

    return NextResponse.json(member)
}

export async function PATCH(req: NextRequest,
                            {params}: { params: { id: string } }
) {
    let where = {id: params.id};
    const values = await req.json()
    const member = await db.member.update({
        where,
        data: {
            role: values.role
        }
    })

    return NextResponse.json(member)
}

export async function DELETE(req: NextRequest,
                             {params}: { params: { id: string } }
) {
    let where = {id: params.id};
    const member = await db.member.delete({
        where
    })

    return NextResponse.json(member)
}